﻿var DXTools = { __namespace: true };
DXTools.FormMessage = {


    showFormMessage: function (message, type, iFrame, iframeLoadedCallback) {
        var qs = "text=" + encodeURIComponent(message) + "&type=" + encodeURIComponent(type);

        Xrm.Page.getControl(iFrame).getObject().onload = function () {          
                DXTools.FormMessage.setFormMessageVisible(iFrame, true);
                iframeLoadedCallback();            
        }

        Xrm.Page.getControl(iFrame).setSrc(Xrm.Page.context.getClientUrl() + "/WebResources/dxtools_/FM/FormMessage.htm?data=" + encodeURIComponent(qs));
        
        
    }
   ,

    setFormMessageVisible: function (iFrame, isVislble) {
        var frame = Xrm.Page.getControl(iFrame);
               
        if (isVislble) {
            frame.getObject().contentDocument.getElementById("uxMessageArea").style.display = "block";
            frame.setVisible(true);
            try {
                Xrm.Page.getControl(iFrame).getParent().controls.get(1).setFocus();
            } catch (ex)
            { }
        }
        else {
            frame.getObject().contentDocument.getElementById("uxMessageArea").style.display = "none";
            frame.setVisible(false);
        }

    },

    
    showMessageConfirmation: function (iFrame, SuccessCallBack, CancelCallBack, SuccessLabelOverride, CancelLabelOverride) {
        var frame = Xrm.Page.getControl(iFrame);
        
        var yesButton = frame.getObject().contentDocument.getElementById("uxYes");
        var noButton = frame.getObject().contentDocument.getElementById("uxNo");


        if (SuccessLabelOverride != null && SuccessLabelOverride != "")
            yesButton.value = SuccessLabelOverride;

        if (CancelLabelOverride != null && CancelLabelOverride != "")
            noButton.value = CancelLabelOverride;
        

     
        if (yesButton.addEventListener) {
            yesButton.addEventListener('click', SuccessCallBack, false);
            noButton.addEventListener('click', CancelCallBack, false);
        }
        else if (yesButton.attachEvent) {
            yesButton.attachEvent('onclick', SuccessCallBack);
            noButton.attachEvent('onclick', CancelCallBack);

        }

       
        frame.getObject().contentDocument.getElementById("uxConfirmation").style.display = "block";
    }

,
__namespace: true
};